import { api } from '../boot/axios'
import { PartsImpWork } from './type'
export interface PartsImpWorkFilter {
  doc_name?:string
  invalid?: number
  parts?:number|string
}

function url(s: string) {
  if (s==''){
    return ['/api/partsimpwork', ''].join('/')
  }
  return ['/api/partsimpwork', s.replace('/', ''), ''].join('/')
}

export async function listPartsImpWorks(params:PartsImpWorkFilter={}){
  const res = await api({
    url: url(''),
    method: 'get',
    params
  })
  return res.data as PartsImpWork[]
}

export async function getPartsImpWork(id:number,){
  const res = await api({
    url: url(''+id),
    method: 'get',
  })
  return res.data as PartsImpWork
}

export async function patchPartsImpWork(id:number,data:Partial<PartsImpWork>={}){
  const res = await api({
    url: url(''+id),
    method: 'patch',
    data
  })
  return res.data as PartsImpWork
}

export async function createPartsImpWork(data:Partial<PartsImpWork>={}){
  const res = await api({
    url: url(''),
    method: 'post',
    data
  })
  return res.data as PartsImpWork
}


export async function listChildPartsImpWorks(part_ids: number[], invalid:number){
  const res = await api({
    url: url('listChildPartsImpWorks'),
    method: 'post',
    data:{
      part_ids,
      invalid
    }
  })
  return res.data.data as PartsImpWork[]
}
